<template>
  <van-overlay class="van-overlay" v-show="show">
    <div class="wrapper">
      <div class="popop">
        <div class="popop_main">
          <img :src="click_add.img" alt />
          <div class="name">{{click_add.goodsName}}</div>
          <div class="molly">
            <img src="../assets/image/moliy.png" alt />
            <span class="moliy">{{click_add.point}}</span>
          </div>
          <div class="gou">
            <img class="butt" @click="sub(click_add)" src="../assets/image/jian.png" alt="">
            <span><input class="input" type="text" v-model='click_add.num' @input="showNums(click_add)" /></span>
            <!-- <span v-text="click_add.num"></span> -->
            <img class="butt" @click="add(click_add)" src="../assets/image/jia.png" alt="">
          </div>
          <button @click="toBirdOrder(click_add)">兑换</button>
        </div>
        <img class="xx" @click="hiddenShow()" src="../assets/image/close.png" alt="">
      </div>
    </div>
  </van-overlay>
</template>
<script>
import url from "../axios/apiUrl";
import { postRequest } from "../api/index";
import { getRequest } from "../api/indexGet";
export default {
  data() {
    return {
      show: false,
      num: 1,
    };
  },

  props: ["click_add"],

  watch: {
    birdGoods(val, oldVal) {},
  },
  method: {},
  methods: {
    // 关闭弹窗
    hiddenShow() {
      var that = this;
      that.show = false;
      this.$parent.changeDia();
    },
    // 加
    add(click_add) {
      click_add.num = parseInt(click_add.num) + 1;
    },
    // 减
    sub(click_add) {
      if (click_add.num > 1) {
        click_add.num = parseInt(click_add.num) - 1;
      } else {
        click_add.num = 1;
      }
    },
    // 输入框
    showNums(click_add) {
      click_add.num = parseInt(click_add.num);
    },

    // 综合专区兑换
    toBirdOrder(click_add) {
      getRequest(url.userPoint).then((res) => {
        if (res.data.content >= click_add.num * click_add.point) {
          var result = {
            goodsId: click_add.goodsId,
            quantity: click_add.num,
          };
          sessionStorage.setItem("ponitOrder", JSON.stringify(result));
          this.$router.push('/birdWriteOrder')
        } else {
          this.$toast({
            type: "error",
            message: "您的精品积分不足",
            duration: 2000,
            offset: 400,
            showClose: true,
          });
        }
      });
    },
  },
};
</script>

<style lang="less" scope>
.van-overlay {
  background-color: rgba(0, 0, 0, 0.4);
  // opacity: 0.4;
  .wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    .popop {
      width: 6.8rem;
      height: 6.9rem;
      box-sizing: border-box;
      background-color: #fff;
      position: relative;
      color: white;
      // padding: 0.3rem 0.8rem;
      border-radius: 0.34rem;
      text-align: center;
      margin: 0 auto;
      z-index: 3000;
      .popop_main {
        width: 5.66rem;
        height: 5.8rem;
        margin: 0.6rem auto;
        img {
          width: 2.1rem;
          height: 2.1rem;
        }
        .name {
          color: #343434;
          font-weight: bold;
          font-size: 0.32rem;
          margin-bottom: 0.2rem;
          margin-top: 0.2rem;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: clip;
        }
        .molly {
          margin-top: 0.3rem;
          margin-bottom: 0.3rem;
          .moliy {
            color: #1fb808;
            font-size: 0.32rem;
            font-weight: bold;
          }
          img {
            font-size: 0.3rem;
            width: 0.3rem;
            height: 0.3rem;
          }
        }
        .gou {
          display: flex;
          justify-content: center;
          align-items: center;
          margin-bottom: 0.2rem;
          .butt {
            width: 0.68rem;
            height: 0.68rem;
            border-radius: 0.68rem;
            font-size: 0.42rem;
          }
          .input {
            border: none;
            width: 2.68rem;
            height: 0.68rem;
            border-radius: 0.68rem;
            text-align: center;
            color: #343434 !important;
          }
        }
        button {
          width: 5.6rem;
          height: 0.88rem;
          background: #1eb808;
          opacity: 0.88;
          border-radius: 0.44rem;
          border: none;
        }
      }
      .xx {
        width: 0.46rem;
        height: 0.46rem;
        color: #222;
        top: 0;
        right: 0;
        margin-right: 0.3rem;
        margin-top: 0.3rem;
        position: absolute;
      }
    }
  }
}
</style>